<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>已发送消息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<div style="padding:10px">
<table id="messageSend" lay-filter="messageSend"></table>
</div>

<script type="text/html" id="headerToolsBar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">
            <i class="layui-icon layui-icon-delete"></i>
            <span>删除</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="send">
            <i class="layui-icon layui-icon-add-1"></i>
            <span>发送信息</span>
        </a>
        <button type="clears" class="layui-btn layui-btn-sm " lay-event="clears">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </button>
    </div>
    <form class="layui-form" action="" lay-filter="querySendForm" style="margin-right: 30px;">
        <div class="layui-row" style="margin-top: 10px;">
            <div class="selch table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label" style="width:66px;padding:9px 3px">标题</label>
                    <input type="text" name="Q_subject_SL" class="layui-input subject filter-value" placeholder="标题"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label" style="width:auto">发送时间</label>
                    <input type="text" name="Q_beginsendTime_DL" autocomplete="off" placeholder="发送时间"
                           class="layui-input start_time filter-value">
                    <label class="layui-form-label" style="width:auto">至</label>
                    <input type="text" name="Q_endsendTime_DG" autocomplete="off" placeholder="结束时间"
                           class="layui-input end_time filter-value">
                </div>
            </div>
        </div>
    </form>
</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="rightToolsBar">
    {{# if(d.edit==1) {  }}
    <a class="layui-btn layui-btn-xs" lay-event="edit" style="margin-right: 10px;">编辑</a>
    {{#  } }}
    <a class="layui-btn layui-btn-xs" lay-event="detail" style="margin-right: 10px;">明细</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="margin-right: 10px;">删除</a>
</script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'form', 'util','laydate', 'setter','totalFilter','commons','common'], function () {
        var util = layui.util;
        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.jquery;
        var table = layui.table;
        var setter = layui.setter;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var max = null;
        var totalFilter = layui.totalFilter;
        commons=layui.commons;
        common=layui.common;
        var tableHeight='full-70';
        var tableHeight=commons.tabHeight(tableHeight);
        //初始化表格
        table.render({
            elem: '#messageSend'
            , url: serverPath.systemPath +setter.sysLinkPath +'messageSend/list'
            , page: true //开启分页
            ,defaultToolbar: ['filter', 'print']
            , toolbar: '#headerToolsBar'
            , title: '数据库表信息'
            , height: tableHeight
            , method: 'post'
            , cols: [[ //表头
                {type: 'checkbox'},
                {field: 'subject', title: '标题', sort:true}
                , {field: 'messageType', title: '消息类型',templet: function (d) {

                        if (d.messageType == '1') {
                            return '个人信息';
                        }
                        if (d.messageType == '2') {
                            return '日程安排';
                        }
                        if (d.messageType == '3') {
                            return '计划任务';
                        }
                        if (d.messageType == '4') {
                            return '系统信息';
                        }
                        if (d.messageType == '5') {
                            return '代办提醒';
                        }
                        if (d.messageType == '6') {
                            return '流程提醒';
                        }
                        return '';}
            }
                 ,{
                    field: 'sendTime', title: '发送时间',
                    sort: true,templet:function(d){
                        if (d.sendTime == undefined) {
                            return "";
                        }else {
                            return util.toDateString(d.sendTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }

                }
                , {
                    field: 'receiverName', title: '收信人',sort: true ,templet:function (d) {
                        var receiverNameStr ='';
                        if(d.receiverName) {
                            receiverNameStr += d.receiverName
                        }
                        if (d.receiverOrgName) {
                            receiverNameStr += d.receiverOrgName
                        }
                        if(receiverNameStr!=''){
                            return receiverNameStr;
                        }else {
                            return "<span style='color: red'>无</span>"
                        }
                    }
                }
                , {
                    field: 'edit', title: '是否',hide:true,
                    sort: true
                }
                , {
                    fixed: 'right',
                    align: 'center',
                    title: '操作',
                    toolbar: '#rightToolsBar'
                }
            ]],
            done: function () {
                reflashDate();
                table.resize()
            }
        });
        totalFilter.init('messageSend');
        reflashDate();
        /*刷新时间控件*/
        function reflashDate() {
            var start = laydate.render({
                elem: '.start_time',
                type: 'date',
                //format: 'yyyy-MM-dd',
                max: nowTime,
                done: function (value, date, endDate) {
                    endMax = end.config.max;
                    end.config.min = date; //最大时间为结束时间的开始值  
                    end.config.min.month = date.month - 1;
                    $("input[name='start_time']").val(value);
                }
            });
            var end = laydate.render({
                elem: '.end_time',
                type: 'date',
                max: 4073558400000,
                format: 'yyyy-MM-dd',
                // min: nowTime,
                done: function (value, date) {
                    if ($.trim(value) == '') {
                        var curDate = new Date();
                        date = {
                            'date': curDate.getDate(),
                            'month': curDate.getMonth() + 1,
                            'year': curDate.getFullYear()
                        };
                    }
                    start.config.max = date; //最小时间为开始时间的最大值  
                    start.config.max.month = date.month - 1;
                    $("input[name='end_time']").val(value);
                }
            })
        }

        //监听头工具栏事件
        table.on('toolbar(messageSend)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'send':
                    $(this).attr("href", serverPath.systemPath+setter.sysLinkPath+"messageSend/view/send");
                    // parent.$("a[lay-href='/system/messageSend/view/send']").click()
                    break;

                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请先选择一行数据！');
                    } else {
                        layer.confirm('确定删除当前数据吗？', function () {
                            var seleIds = [];
                            for (var i = 0; i < data.length; i++) {
                                seleIds.push(data[i].id);
                            }
                            $.ajax({
                                url: serverPath.systemPath + setter.sysLinkPath + "messageSend/del",
                                type: "post",
                                dataType: 'json',
                                data: {id: seleIds.join(",")},
                                success: function (data) {
                                    if (commons._filterRecord(data)) {
                                        layer.alert(data.msg);
                                        table.reload('messageSend', {
                                            page: {curr: 1, limit: 10},
                                        });

                                        totalFilter.init('messageSend');
                                        reflashDate();
                                    } else {
                                        layer.alert(data.msg);
                                    }
                                }
                            })
                            return false;
                        });
                    }
                    break;
                case 'query':
                    common.tableConditionRender("messageSend","querySendForm",{where:{}},false);
                    reflashDate();
                    break;
                case 'clears':
                    common.tableConditionRender("messageSend","querySendForm",{where:{}},true);
                    reflashDate();
                    break;
            }
        });
        //监听行管理
        table.on('tool(messageSend)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'edit':
                    $(this).attr("href",  serverPath.systemPath + setter.sysLinkPath+"messageSend/view/edit?messageId="+data.id);
                    break;
                case 'detail':
                    $(this).attr("href",  serverPath.systemPath +  setter.sysLinkPath+"messageSend/view/get?id="+data.id);
                    break;
                case 'del':
                    layer.confirm('确定删除当前数据吗？',function (index) {
                        layer.close(index);
                        $.ajax({
                            url: serverPath.systemPath + setter.sysLinkPath + "messageSend/del",
                            type: "get",
                            dataType: 'json',
                            data: {id: obj.data.id},
                            success: function (data) {
                                if (commons._filterRecord(data)) {
                                    layer.alert(data.msg);
                                    table.reload('messageSend', {
                                        page: {curr: 1, limit: 10}
                                    });
                                    totalFilter.init('messageSend');
                                    reflashDate();
                                } else {
                                    layer.alert(data.msg);
                                }
                            }
                        });
                        return false;
                    })
                    break;

            }

        });
        common.tableSort("messageSend");
    });
</script>
</body>
</html>